import { userAccountLogin } from '@/api/user'
const user = {
  namespaced: true, // 命名空间
  state: {
    profile: {}
  },
  mutations: {
    // 存入数据
    setUserProfile (state, userInfo) {
      state.profile = userInfo
    },
    // 清空数据
    clearProfile (state) {
      state.profile = {}
    }
  },
  actions: {
    async doLogin (ctx, { account, password }) {
      // 1. 发送登录请求
      const res = await userAccountLogin({ account, password })
      // 2. 拿到token之后 调用mutation存入state
      ctx.commit('setUserProfile', res.data.result)
    }
  }
}
export default user
